extends CanvasLayer


signal start_game


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

func show_message(text):
	$Message.text = text
	$Message.show()
	$MessageTimer.start()


func show_game_over():
	show_message("Game Over!")
	await $MessageTimer.timeout

	$Message.text = "Dodge the Creeps!"
	$Message.show()
	# 动态创建一个1秒的定时器
	# 这让游戏标题在屏幕上显示1秒钟
	# 这个额外的等待给玩家时间阅读游戏标题
	await get_tree().create_timer(1.0).timeout
	# 最后显示开始按钮
	# 玩家可以点击这个按钮重新开始游戏
	# 根据之前连接的信号，点击按钮会触发 start_game 信号
	$StartButton.show()


func update_score(score):
	$ScoreLabel.text = str(score)

func _on_start_button_pressed() -> void:
	$StartButton.hide()
	start_game.emit()


func _on_message_timer_timeout() -> void:
	$Message.hide()
